<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/axios.js"></script>
</head>

<body>
    省<input type="text" name="" id="province" value="浙江省">
    市<input type="text" name="" id="city" value="杭州市">
    <button>查询</button>
    <ul class="list">
        <li></li>
    </ul>
    <script>
        // 获取元素
        const province = document.querySelector('#province')
        const city = document.querySelector('#city')
        const btn = document.querySelector('button')
        const list = document.querySelector('.list')
        // 给btn绑定点击事件
        btn.addEventListener('click', async function () {
            // 定义pname,cname各为input框里的值
            const pname = province.value
            const cname = city.value
            // 发送请求
            const { data: res } = await axios({
                url: 'http://ajax-api.itheima.net/api/area',
                method: 'GET',
                params: {
                    // 让参数为input框的value值，如果参数=变量名的话可以省略写
                    pname,
                    cname,
                },
            })
            list.innerHTML = res.data.map((item) => {
                return `<li>${item}</li>`
            }).join('')

        })
    </script>

</body>

</html>